package homework;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created by Administrator on 2017/8/4 0004.
 */
public class Teacher {
    private Integer id;

    private String name;

    /**
     * 待选课程
     */
    private static List courseList;

    private static Scanner sc;

    static  {
        courseList = new ArrayList();
        sc = new Scanner(System.in);
    }

    /**
     * 添加课程
     *
     */
    public static void  courseAdd(){
        System.out.println("*************************************课程信息录入**************************************");
        while (true) {
            System.out.print("请输入课程编号：");
            int id = sc.nextInt();
            System.out.print("请输入课程名称：");
            String name = sc.next();
            Course course = new Course(id,name);
            courseList.add(course);
            System.out.print("是否继续添加(y/n):");
            String flag = sc.next();
            if(flag.equals("n")) {
                break;
            }
        }
        showList();
    }

    /**
     * 课程列表
     */
    public static  void  showList() {
        System.out.println("*************************************课程列表**************************************");
        for(Object obj : courseList){
            Course course = (Course)obj; //object强转成course
            System.out.println(course.getId() +"." + course.getName() );
        }
        System.out.println("1.添加课程 2.删除课程 3.修改课程");
        System.out.print("请输入要执行的操作:");
        int i = sc.nextInt();
        switch (i) {
            case 1 : Teacher.courseAdd();break;
            case 2 :Teacher.courseDel();break;
            case 3 :Teacher.courseUpdate();break;
            default: showList();
        }
    }

    /**
     * 删除课程
     */
    public static void courseDel(){
        System.out.println("*************************************课程删除**************************************");
        System.out.println("请输入要删除的课程编号：");
        int i = sc.nextInt();
        courseList.remove(i - 1);
        System.out.println("删除成功！");
        showList();
    }

    /**
     * 课程修改
     */
    public static void courseUpdate(){
        System.out.println("*************************************课程修改**************************************");
        System.out.println("请输入要修改的课程编号：");
        int i = sc.nextInt();
        System.out.println("请输入要修改后的课程名称：");
        String name = sc.next();

        courseList.set(i - 1, new Course(i ,name));
        System.out.println("修改成功！");
        showList();

    }
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List getCourseList() {
        return courseList;
    }

    public void setCourseList(List courseList) {
        this.courseList = courseList;
    }
}
